<?php
if (!defined('MODULE_FILE')){
	die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();

// display( $_REQUEST );
// display( $_POST ); exit;

if( false == isset( $_POST['Submit'] ) || false == valStr( $_POST['patient_id'] ) ) { 
	$str = '';
	$str .= '<form name=myform method=post action=modules.php?file=hospital&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
	$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
	echo $str;
	exit;
}

if( true == isset( $_POST['operation'] ) && 'insert' == strtolower( $_POST['operation'] ) ) {
    $objBaseXrays 	= new BaseXrays();

	$objBaseXrays->setPatientId( $_POST['patient_id'] );
	$objBaseXrays->setDoctorId(1);
	$objBaseXrays->setCasePaperId(1);
	$objBaseXrays->setSubject( $_POST['testname1'] );
	$objBaseXrays->setDescription( $_POST['description1'] );
	$objBaseXrays->setChargesAmt( $_POST['testamt1'] );
	$objBaseXrays->setDocumentAttachmentPath(1);
	$objBaseXrays->setAttachmentId(1);
	
	if( 1 == $objBaseXrays->insert() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_hospital&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
} else if( true == isset( $_POST['operation'] ) && 'update' == strtolower( $_POST['operation'] ) ) {
	$objXrays 	= new Xrays();
	$objBaseXrays 	= $objXrays->fetchXraysById( $_POST['hospital_id'] );
	
	$objBaseXrays->setPatientId( $_POST['patient_id'] );
	$objBaseXrays->setDoctorId( 1 );
	$objBaseXrays->setCasePaperId( 1 );
	$objBaseXrays->setSubject( $_POST['testname1'] );
	$objBaseXrays->setDescription( $_POST['description1'] );
	$objBaseXrays->setChargesAmt( $_POST['testamt1'] );
	$objBaseXrays->setDocumentAttachmentPath( 1 );
	$objBaseXrays->setAttachmentId( 1 );

	if( 1 == $objBaseXrays->update() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_hospital&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
}

?>